import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter_echarts/flutter_echarts.dart';
import 'package:get/get.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/services/site/site_services.dart';

/**
 *
 * @Description TODO
 * @Author liuer
 * @CreateTime 2024年04月07日 11:12
 */
class EsPowerLineChart extends StatelessWidget {
  List<dynamic> power;//收益
  EsPowerLineChart({
    super.key,
    required this.power,
  });


  @override
  Widget build(BuildContext context) {

    return Echarts(
      captureHorizontalGestures: true,
      option: '''
 {
  color: ['#3DD598', '#007DFF'],
  /// 横轴
  xAxis: {
    type: 'category',                
    axisLine:{
      show: false,
    }, 
    
    axisTick: {
      show: false
    }, 
    axisLabel: {
      color: '#999999',
      fontSize: 11,
      interval: function (index) { // 自定义间隔函数 
          if (index % 48 === 0) { // 每四小时显示一次  // 返回值是五分钟为一个间隔
              return true;
          } else {
              return false;
          }
      },
    },
  },
  yAxis: [
  
    {
      type: 'value',
      name: ${jsonEncode('${ResKey.unit.tr}(kW)')},
      nameTextStyle: {
        align: "center"
      },
      align: 'left',
       alignTicks: true,
      padding: [3, 4, 5, 6],
      verticalAlign: 'top',
      nameLocation: 'end',
      position: 'left',
      splitLine: {
        lineStyle: {
          type: 'dashed', //虚线
        },
      },
    },
  ],
  grid: {
    top: 30,
    bottom: 45,
    containLabel: true,
    right: 20,
    left: 0,
  },
  legend: {
    show: true,
    icon: 'rect',

    bottom:0,
    itemHeight: 3,
    itemWidth: 12,
     textStyle: {
      borderRadius: [2, 2, 2, 2]
    },
    padding: [
    0,  // 上
    0, // 右
    0,  // 下
    0, // 左
]
  },
  tooltip: {
    trigger: 'axis',
    backgroundColor: 'rgba(0,0,0,0.85)',
    borderWidth: 0,
    opacity: 0.2,
    confine: true,
    padding: [
      10, // 上
      8, // 右
      10, // 下
      8 // 左
    ],
    textStyle: {
      color: 'white'
    },
  },
  dataZoom: [
    {
      type: 'inside',
      realtime: false,
    },
  ],
  series: [
     {
      name: ${jsonEncode(ResKey.totalPowerEss.tr)},
      color: '#0984F9',
      type: 'line',
      yAxisIndex: 0,
      symbol: 'none', // 这里隐藏了折线图中的圆点
      data: ${jsonEncode(power)},
    },
  
  ],
}
  ''',
    );
  }
}
